package com.example.superoa.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.superoa.model.pojos.Department;
import com.example.superoa.model.pojos.Jobchage;
import com.example.superoa.model.pojos.Position;
import com.example.superoa.model.pojos.Staff;
import com.example.superoa.model.pojos.Transfer;
import com.example.superoa.model.pojos.TransferApproval;
import com.example.superoa.model.pojos.TransferJl;
import com.example.superoa.model.pojos.TransferType;
import com.example.superoa.model.service.TransferService;
import com.example.superoa.model.vo.TransferVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@Controller
public class TransferController {
	@Autowired
	private TransferService traservice;
	
	@RequestMapping("ljj-transferadd")
	public void LjjTransferadd() {
		
		
	}
	
	///下拉框根据名字查询员工基本信息
	@RequestMapping("transfers-name")
	@ResponseBody
	public TransferVo transferName(@Param("staff_id")int staff_id) {
		System.err.println(traservice.transferName(staff_id));
		return traservice.transferName(staff_id);
		
	}
	
	//新增调动信息
	@PostMapping("insert-transfer")
	public String addtransfer(Integer depart_id,Integer jobchage_id,Integer positionId,
			Integer departNamea,Integer jobchageNamea,Integer position_name,
			Transfer t,TransferType type,TransferApproval tl,TransferJl tjl,Staff s,
			Integer transfer_id,Integer transfertypesId) {
		//需要新增调动表、调动记录表、调动审批表、调动类型表、以及修改职位部门、职务信息
		int id=traservice.selectIID();
		int jlid=traservice.selectjlIID();
		traservice.addtransfer(id, t, s,transfer_id);
		traservice.addTransferJl(jlid, 0, departNamea, position_name, tjl, id);
		TransferJl newtjl=new TransferJl();
		traservice.addTransferJl(0,jlid,depart_id,positionId,newtjl,id);
		traservice.addTransferApproval(tl, id);
		traservice.addtransfertype(type, id,transfertypesId);
		
		return "redirect:main-administrator:ljj-transfer";
	}
	
	//调动前调动后
	@RequestMapping("transfer-list")
	@ResponseBody
	public JSONArray selectransfer(/*int page,int rows*/){
	/*	Map<String,Object> map = new HashMap<>();
		//先分页
		Page<Object> pg = PageHelper.startPage(page, rows);
		
		JSONArray i=traservice.selectransfer();
		//总记录
		map.put("total", pg.getTotal());
		//页内容
		map.put("rows", i);*/
		return traservice.selectransfer();
	}
	//调动结果
	@RequestMapping("transfer-listjg")
	@ResponseBody
	public JSONArray selectransferjg() {
		return traservice.selectransferjg();
	}
	//调动
	@PostMapping("shenhe-transfer")
	@ResponseBody
	public void transferstate(String approval_state,int approval_id) {
		traservice.transferstate("已调动", approval_id);
	}
	
	@RequestMapping("zizeng-bianhao")
	@ResponseBody
	public List<Transfer> transferALId(){
		System.out.println(traservice.addsid());
		return traservice.transferALId();
	}
	//根据ID查询数据
	@RequestMapping("transfer-Byid")
	@ResponseBody
	public TransferVo selectransferById(Integer Approval_id) {
		System.err.println(Approval_id);
		return traservice.selectransferById(Approval_id);
	}
}
